<!--
 * @Author: lmk
 * @Date: 2021-11-29 17:54:26
 * @LastEditTime: 2021-12-03 13:58:15
 * @LastEditors: lmk
 * @Description: 
-->
<template>
	<view  :class="currentTheme">
		<a-nabbar name="切换身份"/>
		<view class="item-center u-flex u-row-center">
			<item-image :img="`${aliosCdn}/larp/common-${currentTheme}/changeAuth.png`" width="403" height="388"></item-image>
		</view>
		<view class="u-padding-left-32 u-padding-right-32">
			<item-btn  @click="changeAuth" width="100%" height="88">切换{{loginForm.userType==='issue' ? '身份' : '为发行'}}</item-btn>
		</view>
	</view>
</template>

<script>
	import {
		updateUserType
	} from '@/api/user.js'
	export default {
		data() {
			return {
				
			};
		},
		methods: {
			changeAuth() {
				console.log(111)
				const userType = this.loginForm.userType || 'store'
				uni.showModal({
					content: `是否切换${userType==='store' ? '为发行' : '身份'}`,
					confirmText: '是',
					cancelText: '否',
					title: '温馨提示',
					success: ({
						confirm
					}) => {
						if (!confirm) return false;
						
						updateUserType({
							uid: this.loginForm.uid,
							userType: userType === 'store' ? 'issue' : 'store'
						}).then(res => {
							uni.setStorageSync('onlyShowOneTime',1)
							this.$u.toast('切换成功')
							this.$store.dispatch('getInfo').then(({
								hxPassword,
								hxUsername
							}) => {
								getApp().globalData.close(); // 刷新环信账号
								// getApp().globalData.login({hxPassword,hxUsername})
							}); //更新用户信息;
							setTimeout(() => {
								this.$u.route({
									type: "switchTab",
									url: '/pages/index/index'
								})
							}, 300);
						})
					}
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
.item-center{
	margin:189rpx auto 307rpx
}
</style>
